package com.vite.common.password;

import org.passay.*;
import com.vite.common.constant.UserConstants;

/**
 *密码强度校验
 * <a href="http://www.passay.org/javadocs/"/a>
 */
public class PasswordValidUtil {
    public static boolean checkPasswordUnValid(String password) {

        PasswordValidator validator = new PasswordValidator(
                //密码长度
                new LengthRule(UserConstants.PASSWORD_MIN_LENGTH, UserConstants.PASSWORD_MAX_LENGTH),
                new CharacterCharacteristicsRule(3,
                        // 至少有一个英文字母
                        new CharacterRule(EnglishCharacterData.Alphabetical, 1),
                        // 至少有一个大写字母
//                        new CharacterRule(EnglishCharacterData.UpperCase, 1),
                        // 至少有一个小写字母
//                        new CharacterRule(EnglishCharacterData.LowerCase, 1),
                        // 至少有一个特殊字符
                        new CharacterRule(EnglishCharacterData.Special, 1),
                        // 至少有一个数字
                        new CharacterRule(EnglishCharacterData.Digit, 1)
                ));
        RuleResult ruleResult = validator.validate(new PasswordData(password));
        return !ruleResult.isValid();
    }
}
